<div class="layui-fluid layui-anim febs-anim" id="febs-teacherProject" lay-title="课程项目">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">

                    <form class="layui-form layui-table-form" lay-filter="teacherProject-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
<!------------------------------------------查询条件------------------------------------------>
                            </div>

                          <!--  <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query"
                                     onclick="query()">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="teacherProject:view">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>-->
                        </div>
                    </form>

                    <table lay-filter="teacherProjectTable_table" ></table>

                </div>
            </div>
        </div>
    </div>
</div>

<script data-th-inline="javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect','upload','element'], function () {
        var $ = layui.jquery,
            element = layui.element,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#febs-teacherProject'),
            $query = $view.find('#query'),
            courseId = [[${courseId}]],
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            upload = layui.upload,
            selectValue,
            tableIns;
        form.render();
        initTable();

        //查询按钮的点击方法
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        function getQueryParams() {
            return {
                deptId: $("#deptID").val(),
            };
        }

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'teacherProjectTable_table',
                url: ctx + 'studentProject/list?courseId='+courseId,
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'projectName', title: '项目名称', minWidth: 100},
                        {field: 'projectContent', title: '项目描述',},
                        {title: '所属实验课程', field: 'courseName'},
                        {
                            field: 'reportUrl', title: '实验报告',width:200,align:'center', templet: function (d) {
                                return '<button type="button" class="layui-btn layui-btn-normal layui-btn-warm layui-btn-disabled layui-btn-sm" lay-event="view">开始上课</button>';
                            }
                        }
                        /*{title: '状态', templet: '#user-status'}*/
                        /*    {field: 'create_time', title: '创建时间', minWidth: 180, sort: true},*/
                ]
                ]
            })
        }

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('teacherProjectTable_table');
                if (name === 'add') {
                    febs.modal.open('添加实验项目', 'system/teacher/teacherProject/add', {
                        btn: ['提交', '重置'],
                        area: ["50%", "80%"],
                        yes: function (index, layero) {
                            $('#add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的实验项目');
                    } else {
                        febs.modal.confirm('删除实验项目', '确定删除该实验项目？', function () {
                            var userIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                userIds.push(item.teacherProjectId)
                            });
                            deleteTeacherProject(userIds.join(','));
                        });
                    }
                }
            },
        });
        table.on('tool(teacherProjectTable_table)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除实验项目', '确定删除该实验项目？', function () {
                    deleteTeacherProject(data.teacherProjectId);
                });
            }
            if (layEvent === 'report') {
                window.location.href = "/studentProject/downloadReport?url="+data.reportUrl;
            }
            if(layEvent === 'view'){
                febs.modal.view(' ', ctx + 'myProjectView/' + data.projectId, {
                    area: ["100%","100%"]
                });
            }


        });

        function deleteTeacherProject(teacherProjectId) {
            febs.get(ctx + 'teacherProject/delete/' + teacherProjectId, null, function () {
                febs.alert.success('删除课程成功');
                $query.click();
            });
        }
    })
</script>






